package com.feiyisuo.sso.utils;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;

public class WebUtils {
    /**
     * 将字符串渲染到客户端
     *
     * @param response 渲染对象
     * @param string   待渲染的字符串
     * @return null
     */
    public static String renderString(HttpServletResponse response, String string, int status) {
        try {
            response.setStatus(status);
            response.setContentType("application/json;charset=utf-8");
            response.setCharacterEncoding("utf-8");
            response.getWriter().print(string);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 处理请求的url路径
     * @param request
     * @return
     */
    public static String pathUrlDispose(HttpServletRequest request){
        return request.getRequestURI()
                .substring(request.getContextPath().length());
//                .replaceAll("[/]+$", "");
    }
}
